Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Split from #9038. This PR will likely need to be reopened against master once #10159 is merged, but it exists to track the progress of lint plugins.
@ahejlsberg @mhegazy @rbuckton @vladima
Lint plugins exist to provide a simple way to efficiently add style and sanity checks to a project. In-house, we've been a little dissatisfied with
tslint
's performance, and it's obvious that to conserve as many resources as possible and achieve the maximum performance possible, lints aught to be built into the compiler, so they can share the work the compiler is already doing, report errors in a uniform way, and benefit from a condensed single-pass architecture. The design (namely the separation between syntactic and semantic lint passes) was inspired by Rust's lint extension API.Lint plugins as they currently stand take the form of class-like functions (though a factory function will work, too) with a
visit
method and an optionalafterVisit
method.visit
gets called with a node as the walker descends through the tree, along with anerror
function which can be used for error reporting. The error function has a wealth of overloads which allow setting the error level, a shortcode to associate with the error message, the location of the error message, and the message itself. A walker may returntrue
in itsvisit
function to indicate that it no longer needs to recur down into the tree at a given point. If all lints do not needs to visit a portion of the tree, then that portion of the walk is skipped.This is mostly a straight cut from the original PR, things to do from our internal discussion yesterday:
getSyntacticDiagnostics
andgetSemanticDiagnostics
, so getting semantic/syntactic diagnostics no longer triggers a lint. (This way they can be queried less frequently than standard diagnostics.)tsserver
to query for lint diagnostics. (This means editors will need to opt-in to showing lint errors, and decide for themselves how frequently to query for them.)Additionally, lint extensions will need to be updated to have quick fix support once #9304 is merged.